<template>
  <el-form :model="formData" label-width="120px" ref="form" v-loading="loading" class="pr-4">
    <el-form-item label="标题" prop="jump_title" :rules="[{ required: true, message: '标题必须填写' }]">
      <el-input v-model="formData.jump_title" name="jump_title" clearable />
    </el-form-item>
    <el-form-item label="放行地区" prop="jump_country" :rules="[{ required: true, message: '放行地区必须填写' }]">
      <el-select
        v-model="formData.jump_country"
        filterable
        reserve-keyword
        placeholder="请选择放行地区"
        style="width: 240px"
        multiple='true'
        clearable
      >
        <el-option
          v-for="item in countryList"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
    </el-form-item>

    <el-form-item label="屏蔽电脑" prop="ban_computer">
      <el-switch v-model="formData.ban_computer" name='ban_computer' :active-value='2' :inactive-value='1'/>
    </el-form-item>
    <el-form-item label="屏蔽平板" prop="ban_tablet">
      <el-switch v-model="formData.ban_tablet" name='ban_tablet' :active-value='2' :inactive-value='1'/>
    </el-form-item>
    <el-form-item label="屏蔽手机" prop="ban_mobile" >
      <el-switch v-model="formData.ban_mobile" name='ban_mobile' :active-value='2' :inactive-value='1'/>
    </el-form-item>
    <el-form-item label="ip白名单" prop="ip_whitelist" >
      <el-input v-model="formData.ip_whitelist" name="ip_whitelist" placeholder="多个IP 使用 '|' 隔开" clearable />
    </el-form-item>
    <el-form-item label="真实页面" prop="valid_url" :rules="[{ required: true, message: '链接必须填写' }]">
      <el-input v-model="formData.valid_url" name="valid_url" clearable />
    </el-form-item>

    <el-form-item label='审核页面' prop='false_url' :rules="[{ required: true, message: '链接必须填写' }]">
      <el-input v-model='formData.false_url' name='false_url' />
    </el-form-item>
    <div class="flex justify-end">
      <el-button type="primary" @click="submitForm(form)">{{ $t('system.confirm') }}</el-button>
    </div>
  </el-form>
</template>

<script lang="ts" setup>
// @ts-nocheck
import { useCreate } from '@/composables/curd/useCreate'
import { useShow } from '@/composables/curd/useShow'

import { onMounted } from 'vue'

const props = defineProps({
  primary: [Number, String],
  api: String,
  countryList: Object
})

const { formData, form, loading, submitForm, close } = useCreate(props.api, props.primary)

if (props.primary) {
  useShow(props.api, props.primary, formData)
}
const emit = defineEmits(['close'])

onMounted(() => {
  close(() => emit('close'))
})

const options = [
  { label: '正常', value: 1 },
  { label: '禁用', value: 2 }
]
</script>
